R Markdown

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.

When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

summary(cars)
##      speed           dist       
##  Min.   : 4.0   Min.   :  2.00  
##  1st Qu.:12.0   1st Qu.: 26.00  
##  Median :15.0   Median : 36.00  
##  Mean   :15.4   Mean   : 42.98  
##  3rd Qu.:19.0   3rd Qu.: 56.00  
##  Max.   :25.0   Max.   :120.00

Including Plots

You can also embed plots, for example:

Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.

library(sf)
## Linking to GEOS 3.9.0, GDAL 3.2.1, PROJ 7.2.1
library(tidyverse)
## -- Attaching packages --------------------------------------- tidyverse 1.3.1 --
## v ggplot2 3.3.3     v purrr   0.3.4
## v tibble  3.1.1     v dplyr   1.0.5
## v tidyr   1.1.3     v stringr 1.4.0
## v readr   1.4.0     v forcats 0.5.1
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()
library(ggspatial)
library(ggthemes)
library(viridis)
## Loading required package: viridisLite
library(viridisLite)
pops <- st_read("pops.geojson")
## Reading layer `pops' from data source 
##   `C:\Users\itzse\Documents\R\SpatialAnalysis_1\pops.geojson' 
##   using driver `GeoJSON'
## Simple feature collection with 388 features and 34 fields
## Geometry type: POINT
## Dimension:     XY
## Bounding box:  xmin: -74.13974 ymin: 40.57282 xmax: -73.75302 ymax: 40.83362
## Geodetic CRS:  WGS 84
NTA <- st_read("https://services5.arcgis.com/GfwWNkhOj9bNBqoJ/arcgis/rest/services/NYC_Neighborhood_Tabulation_Areas_2020/FeatureServer/0/query?where=1=1&outFields=*&outSR=4326&f=pgeojson", quiet = TRUE)
ggplot(NTA) +
  annotation_map_tile(zoomin = 0, progress = "none", type = "hotstyle")  +
  geom_sf(size = 1, color = "green", fill = "yellow", alpha = 0.3) +
  geom_sf(data = pops, color = "blue", size = 0.1)
## Loading required namespace: raster

  labs(caption = "Map tiles and data by OpenStreetMap")
## $caption
## [1] "Map tiles and data by OpenStreetMap"
## 
## attr(,"class")
## [1] "labels"
ggplot(NTA) +
  annotation_map_tile(zoomin = 0, progress = "none", type = "stamenbw")  +
  geom_sf(size = 0.1, color = "red", fill = "pink", alpha = 0.1) +
  geom_sf(data = pops, color = "green", size = 0.3)

  labs(caption = "Map tiles and data by OpenStreetMap")
## $caption
## [1] "Map tiles and data by OpenStreetMap"
## 
## attr(,"class")
## [1] "labels"
ggplot(NTA) + 
  geom_sf(aes(fill=BoroCode))

ggplot(NTA) + 
  annotation_map_tile(zoomin = 0, progress = "none", type = "stamenbw")  +
  geom_sf(aes(fill = BoroCode)) +
  scale_fill_viridis() + theme_bw() +
  geom_sf(data = pops, color = "red", size = 0.3)

ggplot(NTA) + 
  ggtitle("NYC Neighborhoods and Public Spaces") +
  annotation_map_tile(zoomin = 0, progress = "none", type = "stamenbw")  +
  geom_sf(aes(fill = BoroName)) +
  scale_fill_discrete() + theme_bw() +
  geom_sf(data = pops, aes(color = "Public Spaces"), size = 0.3)

ggplot(NTA) + 
  ggtitle("NYC Neighborhoods and Public Spaces") +
  annotation_map_tile(zoomin = 0, progress = "none", type = "stamenbw")  +
  geom_sf(aes(fill = BoroName)) +
  scale_fill_discrete() + theme_economist() +
  geom_sf(data = pops, aes(color = "Public Spaces"), size = 0.3)

ggplot(NTA) + 
  ggtitle("NYC Neighborhoods and Public Spaces") +
  annotation_map_tile(zoomin = 0, progress = "none", type = "stamenbw")  +
  geom_sf(aes(fill = BoroName), alpha = 0.2) +
  scale_fill_discrete() + theme_clean() +
  geom_sf(data = pops, aes(color = "Public Spaces"), size = 0.3)

ggplot(NTA) + 
  ggtitle("NYC Neighborhoods and Public Spaces") +
  annotation_map_tile(zoomin = 0, progress = "none", type = "stamenbw")  +
  geom_sf(aes(fill = BoroName), alpha = 0.2) +
  scale_fill_discrete() + theme_dark() +
  geom_sf(data = pops, aes(color = "Public Spaces"), size = 0.3)

ggplot(NTA) + 
  ggtitle("NYC Neighborhoods and Public Spaces") +
  annotation_map_tile(zoomin = 0, progress = "none", type = "stamenbw")  +
  geom_sf(aes(fill = BoroName), alpha = 0.2) +
  scale_fill_discrete() + theme_calc() +
  geom_sf(data = pops, aes(color = "Public Spaces"), size = 0.3)

ggplot(NTA) + 
  ggtitle("NYC Neighborhoods and Public Spaces") +
  annotation_map_tile(zoomin = 0, progress = "none", type = "hotstyle")  +
  geom_sf(aes(fill = BoroName), alpha = 0.2) +
  scale_fill_discrete() + theme_classic() +
  geom_sf(data = pops, aes(color = "Public Spaces"), size = 0.3)

ggplot(NTA) + 
  ggtitle("NYC Neighborhoods and Public Spaces") +
  annotation_map_tile(zoomin = 0, progress = "none", type = "cartolight")  +
  geom_sf(aes(fill = BoroName), color = "white", alpha = 0.2) +
  scale_fill_discrete() + theme_clean() +
  geom_sf(data = pops, aes(color = "Privately Owned Public Spaces"), size = 1)